package com.dongnam.quanly.common.dao;

import java.util.List;

import org.hibernate.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dongnam.quanly.common.model.DonHang;
import com.dongnam.quanly.common.model.VatTuHangHoa;
import com.dongnam.quanly.common.model.enumtype.LoaiDonHang;
import com.dongnam.quanly.common.model.enumtype.TrangThaiDonHang;

public class DonHangDao extends ExtendedGenericDao<DonHang, String> {

	private static final Logger logger = LoggerFactory.getLogger(DonHangDao.class);

	public List<VatTuHangHoa> getListMaVthhByDonHang(String donhang) {

		String queryString = "Select vthh from ChiTietDonHang ctdh,VatTuHangHoa vthh "
				+ "where ctdh.vatTuHangHoa = vthh.maVTHH " + "and ctdh.donHang=:sodonhang";
		Query query = getSession().createQuery(queryString);

		query.setParameter("sodonhang", donhang);

		@SuppressWarnings("unchecked")
		List<VatTuHangHoa> list = query.list();

		return list;

	}

	public List<DonHang> getListDonHang(String doitac, TrangThaiDonHang trangthai) {
		String queryString = "Select dh from DonHang dh where dh.doiTac=:doiTac and dh.trangThai=:trangThai";
		Query query = getSession().createQuery(queryString);

		query.setParameter("doiTac", doitac);
		query.setParameter("trangThai", trangthai);

		@SuppressWarnings("unchecked")
		List<DonHang> list = query.list();

		return list;

	}

	public List<DonHang> getListDonHang(TrangThaiDonHang trangthai) {

		String queryString = "Select dh from DonHang dh where dh.trangThai=:trangThai";
		Query query = getSession().createQuery(queryString);

		query.setParameter("trangThai", trangthai);

		@SuppressWarnings("unchecked")
		List<DonHang> list = query.list();

		return list;

	}

	public List<DonHang> getListDonHang(TrangThaiDonHang[] trangthai, LoaiDonHang loaiDonHang) {

		String queryString = "Select dh from DonHang dh where dh.trangThai in (:trangThai) and dh.loaiDonHang=:loaiDonHang";
		Query query = getSession().createQuery(queryString);

		query.setParameterList("trangThai", trangthai);
		query.setParameter("loaiDonHang", loaiDonHang);

		@SuppressWarnings("unchecked")
		List<DonHang> list = query.list();

		return list;

	}
}
